package logic

import (
	"context"
	"library/models/mysql"

	"library/libraryrpc/internal/svc"
	"library/libraryrpc/libraryrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type InformationAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInformationAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InformationAddLogic {
	return &InformationAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *InformationAddLogic) InformationAdd(in *libraryrpc.InformationAddRequest) (*libraryrpc.InformationAddResponse, error) {
	// todo: add your logic here and delete this line

	information := mysql.Information{
		Title:  in.Title,
		Desc:   in.Desc,
		Number: in.Number,
		UserId: int(in.UserId),
	}
	mysql.DB.Create(&information)
	return &libraryrpc.InformationAddResponse{
		InformationId: int64(information.ID),
	}, nil
}
